<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions"%>

<!-- 
<script type='text/javascript'>
function getDepartments() {
  AjaxHandler.getDepartments(createDepartmentsList, document.getElementById("organizationsList").value);
  AjaxHandler.getClientsByOrganization(createClientsList, document.getElementById("organizationsList").value);
}

function getClients() {
  AjaxHandler.getClientsByDepartment(createClientsList, document.getElementById("departmentsList").value);
}

function createDepartmentsList(data) {
  DWRUtil.removeAllOptions("departmentsList");
  DWRUtil.addOptions("departmentsList", [{name:'<fmt:message key = "request.selectDepartment"/>', id: 0}], "id", "name");
  DWRUtil.addOptions("departmentsList", data, "id", "name");
}

function createClientsList(data) {
  DWRUtil.removeAllOptions("clientsList");
  DWRUtil.addOptions("clientsList", [{name:'<fmt:message key = "request.selectClient"/>', id: 0}], "id", "name");
  DWRUtil.addOptions("clientsList", data, "id", "formName");
}
</script>
 -->

<h2><fmt:message key = "form.RequestDetails"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<div id="box">
   <table class = "form">
      <tr>
         <td class = "label"><fmt:message key = "request.status"/></td>
         <td><c:out value = "${requestBean.requestStatus.status}"/></td>
      </tr>
   
      <tr>
         <td class = "label"><fmt:message key = "request.regNumber"/></td>
         <td><c:out value = "${requestBean.regNumber}"/></td>
      </tr>
   
      <tr>
         <td class = "label"><fmt:message key = "request.organization"/></td>
         <td><c:out value = "${requestBean.organization.fullTitle}"/></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.department"/></td>
         <td><c:out value = "${requestBean.department.name}"/></td>
      </tr>
            
      <tr>
         <td class = "label"><fmt:message key = "request.client"/></td>
         <td>
            <c:out value = "${requestBean.client.lastName}"/>&nbsp;
            <c:out value = "${requestBean.client.firstName}"/>&nbsp;
            <c:out value = "${requestBean.client.middleName}"/>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.email1"/></td>
         <td>
            <c:out value = "${requestBean.client.email1}"/>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "client.tel1"/></td>
         <td>
            <c:out value = "${requestBean.client.tel1}" default='---'/><br>
            <c:out value = "${requestBean.client.tel2}"/><br>
            <c:out value = "${requestBean.client.tel3}"/>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.room"/></td>
         <td><c:out value = "${requestBean.room}"/></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.text"/></td>
         <td class = "textField"><c:out value = "${requestBean.clientText}"/></td>
      </tr>     
      
      <tr>
         <td class = "label"><fmt:message key = "request.dispatcherText"/></td>
         <td class = "textField"><c:out value = "${requestBean.dispatcherText}"/></td>
      </tr>

      <tr>
         <td class = "label"><fmt:message key = "request.group"/></td>
         <td><c:out value = "${requestBean.group.name}"/></td>
      </tr>               
      
      <tr>
         <td class = "label"><fmt:message key = "request.requestType"/></td>
         <td><c:out value = "${requestBean.requestType.type}"/></td>
      </tr>            
      
      <tr>
         <td class = "label"><fmt:message key = "request.regDate"/></td>
         <td><fmt:formatDate value="${requestBean.registrationDate}" pattern="dd.MM.yyyy"/></td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.approxEndDate"/></td>
         <td>
           <fmt:formatDate value="${requestBean.approxEndDate}" 
           pattern="dd.MM.yyyy"/>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.realEndDate"/></td>
         <td>
            <fmt:formatDate value="${requestBean.realEndDate}" pattern="dd.MM.yyyy"/>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.leadExecutor"/></td>
         <td>
            <c:out value = "${requestBean.leadExecutor.lastName}"/>&nbsp;
            <c:out value = "${requestBean.leadExecutor.firstName}"/>&nbsp;
            <c:out value = "${requestBean.leadExecutor.middleName}"/> 
         </td>
      </tr>
      <tr>
         <td class = "label"></td>
         <td>
            <c:out value = "${requestBean.leadExecutor.email}"/> 
         </td>
      </tr>
</table>
</div>

<h3><fmt:message key = "task.executors"/></h3>
<table class = "regular">
   <thead>
      <tr>
            <th><fmt:message key = "task.executor"/></th>
            <th><fmt:message key = "task.text"/></th>            
            <th><fmt:message key = "task.startdate"/></th>
            <th><fmt:message key = "task.enddate"/></th>
            <th><fmt:message key = "task.status"/></th>
      </tr>
   </thead>
   
   <tbody>
      <c:forEach var = "task" items = "${tasksList}">
      <tr>
        <td>
           <c:out value = "${task.executor.lastName}"/>&nbsp;
           <c:out value = "${task.executor.firstName}"/>           
        </td>
        
        <td>
           <c:out value = "${fn:substring(task.text, 0, 200)}"/>           
        </td>
        
        <td>
           <fmt:formatDate value="${task.startDate}" pattern="dd.MM.yyyy"/>           
        </td>
        
        <td>
           <fmt:formatDate value="${task.endDate}" pattern="dd.MM.yyyy"/>           
        </td>
        
        <td>
           <c:out value = "${task.status.status}"/>           
        </td>
        
      </tr>
      </c:forEach>
   </tbody>
   
   <tfoot>
      <tr>
         <th colspan = "6">
           <fmt:message key = "task.total"/>:
           <fmt:formatNumber value = '${fn:length(tasksList)}'/>
         </th>
      </tr>
   </tfoot>     
</table>